package com.itheima.test.UDP.unicast;

import java.io.IOException;
import java.net.*;

public class Client {//发送方

    public static void main(String[] args) throws IOException {
        //创建码头,无参则随机端口发送
        DatagramSocket socket = new DatagramSocket();
        //创建数据包裹,并把礼物装在包裹中
        String s ="送给村长的礼物";
        byte[] bytes = s.getBytes();
        InetAddress address = InetAddress.getByName("127.0.0.1");
        //参数（包裹，包裹长度，接收方，接收方端口）
        DatagramPacket packet = new DatagramPacket(bytes, bytes.length,address,1000);
        //把包裹交给码头
        socket.send(packet);
        //释放资源
        socket.close();
    }
}
